<?php 
class MD_News
{
	public static function getNewsById($id)
	{
		$news = TN_Db::getInstance()->fetchAll("SELECT * FROM news where id = '$id' ");
    	return $news[0];
	} 
	
	public static function getHightNews($limit = '')
	{
		$sql = "select * from news where hightlight = 1 $limit";
		return TN_Db::getInstance()->fetchAll($sql);
	}
	
	public static function getNewsByCategory($c)
	{
		return TN_Db::getInstance()->fetchAll("SELECT * FROM news  where id_category = '$c' ORDER BY publish_date desc");
	}
	
	public static function setImage($id, $img)
	{
		TN_Db::getInstance()->update('news', array('image' => $img), "id = '$id' ");
	}
	
	public static function add( $title, $publish_date , $expired_date  ,$enabled,  $image , $short_desc , $desc ,  $highlight, $category)
	{
		TN_Db::getInstance()->insert('news', array('title'=> $title, 'publish_date' => $publish_date, 'expiration_date' => $expired_date ,'enabled' => $enabled , 'short_description' => $short_desc, 'description' => $description  , 'image' => $image ,'id_category' => $category, 'hightlight' => $highlight));
	}
 	public static function lastId()
    {
    	return TN_Db::getInstance()->lastInsertId('news');
    }
	public static function update($id, $title, $publish_date , $expired_date  ,$enabled,  $image , $short_desc , $desc ,  $highlight, $category)
	{
		TN_Db::getInstance()->update('news', array('title'=> $title, 'publish_date' => $publish_date, 'expiration_date' => $expired_date ,'enabled' => $enabled , 'short_description' => $short_desc, 'description' => $desc  , 'image' => $image ,'id_category' => $category, 'hightlight' => $highlight), "id = '$id' ");
	}
	
	public static function delete ($id )
	{
		TN_Db::getInstance()->delete('news', "id = '$id' ");
	}
}
?>